package com.xinzhi.service.impl;

import com.xinzhi.mapper.TwogradeindexMapper;
import com.xinzhi.pojo.TwoGradeIndex;
import com.xinzhi.service.TwoGradeIndexService;
import com.xinzhi.utils.RedisUtils;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class TwoGradeIndexServiceImpl implements TwoGradeIndexService {
    @Autowired
    private TwogradeindexMapper twogradeindexMapper;
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
//    指标框架制定修改

    @Override
    public Result update(TwoGradeIndex twogradeindex) {
        System.out.println(twogradeindex);
        if (twogradeindex == null || twogradeindex.getTwo_indexid() == null) {
            return Result.error("ID 不能为空");
        }
        redisTemplate.delete("twogradeindex");
        int update = twogradeindexMapper.update(twogradeindex);
        try {
            Thread.sleep(800);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        redisTemplate.delete("twogradeindex");
        redisUtils.get("twogradeindex");
        return update > 0 ? Result.ok("修改成功") : Result.error("修改失败");
    }
}
